I just have a super quick question about JavaScript so I'm not going to follow the general formatting of a question like usual.
I'm trying to understand some code in JavaScript, and the person who wrote it used a method that I'm not familiar with. As you see in the title, they've written it by typing the name of the function followed by a colon first, and then writing the actual function.
Example: myFunction: function () {}
Is anyone able to tell me what this means, why it's done, and what it accomplishes?
It is part of Object Methods like:
const person = {
myFunction: function() {}
};
you can invoke myfunction by using person.myFunction()
There are 3 ways of writing a function in JavaScript:
function myFunction() {} // Function Declaration
myFunction: function () {} // Function Expression
myFunction = () => {} // Arrow Function